//
//  YMMagicCameraVC.m
//  QuPaiYunDemo
//
//  Created by 占益民 on 2018/3/29.
//  Copyright © 2018年 占益民. All rights reserved.
//

#import "YMMagicCameraVC.h"
#import <AVFoundation/AVFoundation.h>
#import <AliyunVideoSDKPro/AliyunVideoSDKPro.h>
#import "YMPathManager.h"
@interface YMMagicCameraVC ()

@property(nonatomic,strong) AliyunIRecorder *recorder;


@end

@implementation YMMagicCameraVC
{
    CGSize _videoSize;
    //录制片段
    AliyunClipManager *_clipManager;
}

-(void)setVideoSize:(CGSize)size{
    _videoSize = size;
}


-(instancetype)init{
    self = [super init];
    if (self) {
        _videoSize = CGSizeMake(540, 960);
        _beauty = YES;
        _faceTrack = YES;
    }
    return self;
}

-(void)loadView{
    [super loadView];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"魔法相机";
    
    //录制
   
    
}


#pragma mark -  lazy init
-(AliyunIRecorder *)recorder{
    if (!_recorder) {
        _recorder = [[AliyunIRecorder alloc] initWithDelegate:self videoSize:_videoSize];
        //预览视图 必须设置
//        _recorder.preview =
        NSString *videoPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/testVideo/preview.mp4"];
        NSString *taskPath = [YMPathManager ym_createMagicRecordDir];
        if ([[NSFileManager defaultManager] fileExistsAtPath:taskPath]) {
            [[NSFileManager defaultManager] removeItemAtPath:taskPath error:nil];
        }
        //视频输出路径
        _recorder.outputPath = videoPath;
        //输出类型
        _recorder.outputType = AliyunIRecorderVideoOutputPixelFormatType420f;
        //文件配置路径
        _recorder.taskPath = taskPath;
        //美颜状态
        _recorder.beautifyStatus = self.beauty;
        //美颜度
        _recorder.beautifyValue = 80;
        //是否开启人脸识别
        _recorder.useFaceDetect = YES;
        //后置摄像头采集分辨率 默认:AVCaptureSessionPreset640x480  更多参数参见：AVCaptureSession.h
        _recorder.backCaptureSessionPreset = AVCaptureSessionPreset1280x720;
        // 前置摄像头采集分辨率 默认:AVCaptureSessionPreset640x480  更多参数参见：AVCaptureSession.h
        _recorder.frontCaptureSessionPreset = AVCaptureSessionPreset1280x720;
        //设置人脸识别个数
        _recorder.faceDetectCount = 2;
        //是否同步贴合人脸
        _recorder.faceDectectSync = NO;
        
        //录制片段设置
        _clipManager = _recorder.clipManager; //视频片段管理
        _clipManager.maxDuration = 15; // 最大时长
        _clipManager.minDuration = 0.5; //最小时长
    }
    return _recorder;
}




@end
